package com.homedo.distributed.id.client.gen.constants;

import java.util.concurrent.*;

public abstract class GenExecutorConstants {
    public static final ExecutorService UPDATE_BUFFER_EXECUTOR = new ThreadPoolExecutor(5, Integer.MAX_VALUE, 60L, TimeUnit.SECONDS, new LinkedBlockingQueue(), new GenExecutorConstants.GenThreadFactory("Thread-GenBuffer-Update-"));
    public static final ExecutorService MONITOR_BUFFER_EXECUTOR = new ThreadPoolExecutor(5, Integer.MAX_VALUE, 60L, TimeUnit.SECONDS, new LinkedBlockingQueue(), new GenExecutorConstants.GenThreadFactory("Thread-GenBuffer-Monitor-"));
    public static final ExecutorService PRE_INIT_BUFFER_EXECUTOR = new ThreadPoolExecutor(1, Integer.MAX_VALUE, 60L, TimeUnit.SECONDS, new LinkedBlockingQueue(), new GenExecutorConstants.GenThreadFactory("Thread-GenBuffer-Pre-Init-"));

    public static class GenThreadFactory implements ThreadFactory {
        private static int threadInitNumber = 0;

        private String prefixName;

        public GenThreadFactory(String prefixName) {
            this.prefixName = prefixName;
        }

        private static synchronized int nextThreadNum() {
            return threadInitNumber++;
        }

        public Thread newThread(Runnable r) {
            Thread thread = new Thread(r, prefixName + nextThreadNum());
            thread.setDaemon(true);
            return thread;
        }
    }
}
